package ist.utl.pt.smartfleet.stationterminal.rest.webservice.traveller;

import ist.utl.pt.smartfleet.stationterminal.rest.webservice.client.RestClient;
import android.util.Log;

public class TravellerWebServiceUtil {

	static final String SERVICE_URL = "/smartfleetcserver/web/services/travellerws";
	static final String SAVE_METHOD = "/save";
	static final String SAVE_TRAVELLER_ON_STATION_METHOD ="/save/onstation";
	static final String UPDATE_STATE_METHOD = "/update/state";
	static final String UPDATE_CHECK_OUT_TIME_METHOD = "/update/checkouttime";

	/**
	 * Este m�todo envia os dados para o central server
	 * 
	 * @param id
	 * @param name
	 * @param state
	 * @param size
	 * @param checkInTime
	 * @param checkOutTime
	 * @param idStation
	 * @param idTrip
	 * @param idLocationDestiny
	 */
	public static void saveOnServer(String id, String name, String state,
			String size, String checkInTime, String checkOutTime,
			String idStation, String idTrip, String idLocationDestiny) {
		try {

			String dataToSend = "/" + id + "/" + name + "/" + state + "/"
					+ size + "/";
			dataToSend += checkInTime + "/" + checkOutTime + "/" + idStation
					+ "/" + idTrip + "/" + idLocationDestiny;

			String finalUrl = SERVICE_URL + SAVE_METHOD + dataToSend;
			String response = RestClient.doGet(finalUrl);

		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}
	}

	/**
	 * Este m�todo envia a actualizacao do estado de um traveller para a o
	 * central server
	 * 
	 * @param id
	 * @param state
	 */
	public static void updateState(String id, String state) {
		try {

			String dataToSend = "/" + id + "/" + state;
			String finalUrl = SERVICE_URL + UPDATE_STATE_METHOD + dataToSend;
			String response = RestClient.doGet(finalUrl);

		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}
	}

	/**
	 * Este m�todo envia a actualizacao do checkoutime para o traveller representado pelo id
	 * @param id
	 * @param checkOutTime
	 */
	public static void updateCheckOutTime(String id, String checkOutTime) {
		try {

			String dataToSend = "/" + id + "/" + checkOutTime;
			String finalUrl = SERVICE_URL + UPDATE_CHECK_OUT_TIME_METHOD + dataToSend;
			String response = RestClient.doGet(finalUrl);
			System.out.println("response from server:"+response);
		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}
	}
	
	public static void saveTravellerCheckedIn(
			String id, String name,String address, String state,
			String size, String checkInTime,  
			String idStation, String destinyLat, String destinyLong) {
		 
		try {

			String dataToSend = "/" + id + "/" + name + "/" + state + "/"+ size 
			+ "/"+checkInTime + "/" + idStation+ "/" + destinyLat + "/" + destinyLong;

			String finalUrl = SERVICE_URL + SAVE_TRAVELLER_ON_STATION_METHOD + dataToSend;
			String response = RestClient.doGet(finalUrl);
			System.out.println("response from server:"+response);
		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}
	}
}
